﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuadRemote.Core;

namespace QuadRemote.Tabs
{
    public partial class ConfigurationPanel : UserControl
    {
        public ConfigurationPanel()
        {
            InitializeComponent();
        }

        void RenderFields()
        {
            valueGroups.TabPages.Clear();

            foreach (String groupName in FlightSession.current().Config.varValues.Keys)
            {
                TabPage tab = new TabPage(groupName);
                valueGroups.TabPages.Add(tab);

                int y = 20;
                foreach (VarValue varValue in FlightSession.current().Config.varValues[groupName])
                {
                    ConfigField newField = new ConfigField(varValue);
                    newField.Top = y;
                    tab.Controls.Add(newField);

                    y += newField.Height + 2;
                }

                tab.Height = y + 10;

            }

        }

        private void btUpdate_Click(object sender, EventArgs e)
        {
            //new CommandOut(CommandId.CMD_CONFIG_SEND_ALL).send();

            //Core.Bluetooth.instance().sendPriorityPacket((byte)Bluetooth.CMD_ID.CMD_CONFIG_SEND_ALL);

            //varValues.Clear();
            RenderFields();
        }

        private void btWriteSD_Click(object sender, EventArgs e)
        {
            new CommandOut(CommandId.CMD_CONFIG_WRITE_SD).send();
            //Core.Bluetooth.instance().sendPriorityPacket((byte)Bluetooth.CMD_ID.CMD_CONFIG_WRITE_SD);

            //varValues.Clear();
        }

        private void btReadSD_Click(object sender, EventArgs e)
        {
            new CommandOut(CommandId.CMD_CONFIG_READ_SD).send();
//            Core.Bluetooth.instance().sendPriorityPacket((byte)Bluetooth.CMD_ID.CMD_CONFIG_READ_SD);

            //varValues.Clear();
        }
    }
}
